package com.amit;

import java.io.IOException;

import javax.servlet.Filter;
import javax.servlet.FilterChain;
import javax.servlet.FilterConfig;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import javax.servlet.annotation.WebFilter;
import javax.servlet.annotation.WebInitParam;


@WebFilter(filterName="demof",urlPatterns={"/demo.jlc"},
		initParams={@WebInitParam(name="city",value="HYD")})
public class DemoFilter implements Filter {

	@Override
	public void init(FilterConfig fc) throws ServletException {
		
		System.out.println("DemoFilter-init()");
		String ci=fc.getInitParameter("city");
		System.out.println(ci);
		
	}
	
	@Override
	public void doFilter(ServletRequest request, ServletResponse response,
			FilterChain chain) throws IOException, ServletException 
			{
	
		System.out.println("DemoFilter-doFilter()");
		String nm=request.getParameter("name");
		String em=request.getParameter("email");
		String ip=request.getRemoteAddr();
		System.out.println(nm);
		System.out.println(em);
		System.out.println(ip);
		System.out.println("DemoFilter-doFilter()-before");
		
		chain.doFilter(request, response);
		System.out.println("DemoFilter-doFilter()-after");
		String msg=request.getAttribute("MSG").toString();
		System.out.println(msg);
		
	}
	
	@Override
	public void destroy() {
	
		System.out.println("DemoFilter-destroy()");
		
	}
	
	
}
